package com.fasteat.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasteat.mall.entity.Product;
import com.fasteat.mall.mapper.ProductMapper;
import com.fasteat.mall.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hy
 * @since 2021-01-19
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

	@Autowired
	private RedisTemplate redisTemplate;

	@Autowired
	private ProductMapper productMapper;

	/**
	 * 通过商品标题获取商品
	 *
	 * @param productTitle
	 * @return
	 */
	@Override
	public List<Product> getByName(String productTitle) {
		QueryWrapper<Product> wrapper = new QueryWrapper<>();
		wrapper.like("%title%", productTitle);
		List<Product> productsList = productMapper.selectList(wrapper);
		return productsList;
	}

	@Override
	public List<Product> listTenGoodCommentProduct() {
		List<Product> list = (List<Product>) redisTemplate.opsForValue().get("TEN_GOOD_PRODUCT");
		return list;
	}

//    /**
//     * 刷新好评率
//     *
//     */
//    @Override
//    public void refreshGoodCommentPercent() {
//        productMapper.refreshGoodComment();
//    }

}
